<template>
    <div>
        <!--顶部滑动条区域-->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id==0?'mui-active':'']" v-for="item in cates" :key="item.id" @click="getPhotoListByCateId(item.id)">
                        {{item.title}}
                    </a>

                </div>
            </div>

        </div>
        <!--图片列表区域-->
        <div id="container">
            <ul class="page-lazyload-list">
                <router-link tag="li" v-for="item in list" :key="item.id" class="page-lazyload-listitem" :to="'/home/photolist/photoinfo/'+item.id">
                    <img v-lazy="item.url" class="page-lazyload-image">
                    <div class="info">
                        <div class="info-body">{{item.describe}}</div>

                    </div>
                </router-link>
            </ul>
        </div>

    </div>

</template>

<script>
    //导入mui.js文件
    import mui from '../../lib/MUI/js/mui.min.js'

    export default {
        name: "photo-list",
        data(){
            return{
                cates:[],
                list:[]//图片列表的数组
            }
        },
        mounted(){//当组件中的dom结构被渲染好并放到页面中后，会执行这个钩子函数
            //2、初始化滑动控件
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        created(){
            this.getAllCategory()

        },
        methods:{
            getAllCategory(){
                this.$http.get('http://192.168.1.237:9090/test33/test.php').then(result=>{
                    if (result.body.code===0){
                        result.body.imgcategory.unshift({title:"全部",id:0,
                            urlInfo:[
                                {"id": 1,"url":"../../images/img/1.jpg","describe":"111"},
                                {"id": 2,"url":"../../images/img/2.jpg","describe":"222"},
                                {"id":3,"url":"../../images/img/3.jpg","describe":"333"},
                                {"id": 4,"url":"../../images/img/4.jpg","describe":"444"},
                                {"id": 5,"url":"../../images/img/5.jpg","describe":"555"},
                                {"id": 6,"url":"../../images/img/1.jpg","describe":"111"},
                                {"id": 7,"url":"../../images/img/2.jpg","describe":"222"},
                                {"id": 8,"url":"../../images/img/3.jpg","describe":"333"},
                                {"id": 9,"url":"../../images/img/4.jpg","describe":"444"}]})
                            this.cates= result.body.imgcategory
                    }
                    this.getPhotoListByCateId(0)
                })
            },
            getPhotoListByCateId(itemId){

                this.cates.forEach(item=>{
                    if (item.id===itemId){
                        this.list=item.urlInfo
                    }
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    *{
        touch-action: pan-y;/*谷歌浏览器为了提高页面的滑动流畅而折腾出来的一个东西*/
    }
    .img_list{
        list-style-type: none;
        padding: 10px;
        padding-bottom: 0;
        margin: 0;
    }
    .page-lazyload-list{
        padding: 0;
        text-align: center;
        .page-lazyload-listitem {
            position: relative;
            list-style: none;
            width: 300px;
            margin: 0 auto;
            margin-bottom: 10px;
            background-color: #ddd;
            box-shadow: 0 0 6px #999;
            .page-lazyload-image {
                display: block;
                width: 100%;
            }
            img[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
            .info{
                position: absolute;
                bottom: 0;
                color: #fff;
                font-size: 13px;
                text-align: left;
                background: rgba(0, 0, 0, 0.5);
                width: 100%;
                max-height: 84px;
            }

        }
    }


</style>